<?php
	// 加载公共文件
	include_once('../../public/config/config.php');
	include_once('../../public/config/sql.php');

	$obj = new sql($info); // 实例化对象
	session_start(); //开启session

	// 接收post传值
	$users = isset($_POST['users']) ? $_POST['users'] : '';
	$pass  = isset($_POST['pass']) ? md5($_POST['pass']) : '';
	$overy = isset($_POST['overy']) ? $_POST['overy'] : '';
	$overyCode = isset($_SESSION['captcha']) ? $_SESSION['captcha'] : '';
	$data = array(); // 初始化

	try{

		if($overy != $overyCode){

			$data = array(

				'code' => '0',
				'msg' => 'ok',
				'overy' => '1'
			);

			// 转换JSON类型数据
			header('Content-Type', 'application/json');
			echo json_encode($data);
			exit;
		}

		// 构建SQL语句、
		$sql = "select username,`password` from administrator where username=? and `password`=?";

		if($obj->db_select_affect($sql, $users, $pass, true)){
			
			$data = array(

				'code' => '1',
				'msg' => 'ok',
				'overy' => '0'
			);

			$_SESSION['users'] = $users;
		}else{

			$data = array(

				'code' => '0',
				'msg' => 'ok',
				'overy' => '0'
			);
			
		}

	}catch(PDOException $e){

		$data = array(
			'code' => '0',
			'msg' => $e->getMessage(),
			'overy' => '1'
		);
	}

	// 转换JSON类型数据
	header('Content-Type', 'application/json');
	echo json_encode($data);

?>